/**
 * This class represent's the player's spaceship, and tracks name, health,
 * shields, cargo, etc.
 * 
 * @author Stanley Ayzenberg, Michelle Partogi, Adam Perez, Araya Zaesim
 * @version 1.0
 */

public class SpaceShip implements java.io.Serializable {

	/**
	 * Field name.
	 */
	private String name = "";

	/**
	 * Field health.
	 */
	private int health = 0;

	/**
	 * Field shields.
	 */
	private int shields = 0;

	/**
	 * Field goods.
	 */
	private int[] goods;

	/**
	 * Field maxCarg.
	 */
	private int maxCarg = 0;

	/**
	 * Field currentCarg.
	 */
	private int currentCarg;

	/**
	 * Field fuel.
	 */
	private int fuel;

	/**
	 * Field maxFuel.
	 */
	private int maxFuel = 0;

	/**
	 * Field maxDistance.
	 */
	private int maxDistance;
	
	/**
	 * toString method.
	 * @return String
	 */
	public String toString() {
		return "";
	}

	/**
	 * Constructor for SpaceShip.
	 * @param shipName String
	 * @param def int[]
	 */
	public SpaceShip(String shipName, int[] def) {
		if (shipName.equals("Gnat")) {
			name = "Gnat";
			health = 100;
			shields = 0;
			goods = def.clone();
			maxCarg = 15;
			maxFuel = 20;
			fuel = 20;
			currentCarg = 0;
			maxDistance = 50;
		}
	}

	/**
	 * Method getMaxDistance.
	
	 * @return int */
	public int getMaxDistance() {
		return maxDistance;
	}

	/**
	 * Method setMaxDistance.
	 * @param maxDistance int
	 */
	public void setMaxDistance(int maxDistance) {
		this.maxDistance = maxDistance;
	}

	/**
	 * Returns the goods in the spaceship
	 * 
	
	 * @return The goods in the spaceship */
	public int[] getGoods() {
		return goods;
	}

	/**
	 * Sets the goods in the spaceship
	 * 
	 * @param newGoods
	 *            The goods in the spaceship
	 */
	public void setGoods(int[] newGoods) {
		goods = newGoods.clone();
		int tempCargo = 0;
		for (int i = 0; i < goods.length; i++) {
			tempCargo += goods[i];
		}
		setCargo(tempCargo);
	}

	/**
	 * Returns whether or not the ship is full of cargo
	 * 
	
	 * @return Whether or not the ship is full of cargo */
	public boolean isFull() {
		return maxCarg == currentCarg;
	}

	/**
	 * Returns whether the ship has no cargo
	 * 
	
	 * @return Returns true if ship has no cargo */
	public boolean isEmpty() {
		return currentCarg == 0;
	}

	/**
	 * Returns the amount of cargo in the ship
	 * 
	
	 * @return The amount of cargo in the ship */
	public int getCargo() {
		int tempCargo = 0;
		for (int i = 0; i < 10; i++) {
			tempCargo+= goods[i];
		}
		return tempCargo;
	}

	/**
	 * Sets the amount of cargo in the ship
	 * 
	 * @param n
	 *            The amount of cargo in the ship
	 */
	public void setCargo(int n) {
		currentCarg = n;
	}

	/**
	 * Sets the amount of fuel in the ship
	 * 
	 * @param fuel
	 *            Amount of fuel in the ship
	 */
	public void setFuel(int fuel) {
		this.fuel = fuel;
	}

	/**
	 * Returns the amount of fuel in the ship
	 * 
	
	 * @return Amount of fuel in the ship */
	public int getFuel() {
		return fuel;
	}

	/**
	 * Returns the maximum amount of fuel in the ship
	 * 
	
	 * @return Maximum amount of fuel in the ship */
	public int getMaxFuel() {
		return maxFuel;
	}

	/**
	 * Returns the maximum cargo spaces in the current spaceship
	 * 
	
	 * @return Maximum number of cargo spaces */
	public int getMaxCargo() {
		return maxCarg;
	}

	/**
	 * Method isFuelFull.
	
	 * @return boolean */
	public boolean isFuelFull() {
		return fuel == maxFuel;
	}

	/**
	 * Updates the fuel level after warping to systems.
	 * 
	 * @param current
	 *            Current solar system.
	 * @param target
	 *            The target solarsystem the player travels to.
	 * @param p
	 *            The player object.
	 */
	public void updateFuelFromTravel(SolarSystem current, SolarSystem target,
			Player p) {
		final double fuelEfficiency = (maxDistance + (p.getPilotPoints() / 1.5))
				/ maxFuel;
		final double distance = target.getDistance(current);
		fuel = fuel - (int) (distance / fuelEfficiency);
	}
}
